﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using DataEntity;
using JScripter;
using BusinessLogic.Controller;

public partial class Admin_AjaxPages_PropertyOwnershipAdd : AjaxPage
{
    private int ID
    {
        get
        {
            if (Request.Params["poid"] != null || AjaxState.ContainsKey("poid"))
            {
                if (!AjaxState.ContainsKey("poid"))
                    AjaxState["poid"] = Request.Params["poid"];
                return Convert.ToInt32(AjaxState["poid"]);
            }
            else
            {
                return 0;
            }
        }
    }


    private void AddData()
    {
        try
        {
            PropertyOwnership objPropertyOwnership = new PropertyOwnership();



            objPropertyOwnership.Name = HtmlHelper.ControlValue(txtName.ClientID);

            objPropertyOwnership.ModifiedDate = DateTime.Now;

            new PropertyOwnershipController().Add(objPropertyOwnership);
            Response.Redirect("~/Admin/AjaxPages/PropertyOwnershipList.aspx");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
        }
    }

    private void EditData()
    {

        PropertyOwnership objPropertyOwnership = new PropertyOwnership();

        objPropertyOwnership.PropertyOwnershipID = ID;

        objPropertyOwnership.Name = HtmlHelper.ControlValue(txtName.ClientID);

        objPropertyOwnership.ModifiedDate = DateTime.Now;

        new PropertyOwnershipController().UpdateByPropertyOwnershipID(objPropertyOwnership);
        Response.Redirect("~/Admin/AjaxPages/PropertyOwnershipList.aspx");
    }

    private void BindData()
    {
        var dataBunch = new PropertyOwnershipController().GetbyPropertyOwnershipID(ID);
        if (dataBunch.Count > 0)
        {
            var data = dataBunch[0];


            txtName.Text = data.Name;



        }
    }

    protected void AddAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        AddData();
        
    }
    public void PreventData()
    {
        txtName.Text = HtmlHelper.ControlValue(txtName.ClientID);
        

    }

    protected void UpdateAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        EditData();
    }
}